package com.wanxi.controller;

import com.alibaba.fastjson2.JSONObject;
import com.wanxi.dto.ResultDTO;
import com.wanxi.service.ImageService;
import com.wanxi.vo.ImageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/image")
@CrossOrigin(origins = "http://localhost:8081")
public class ImageController {
    @Autowired
    ImageService imageService;

    @PutMapping("/add")
    public String addImage(ImageVO imageVO){
        ResultDTO resultDTO = imageService.addImage(imageVO);
        return JSONObject.toJSONString(resultDTO);
    }

    @DeleteMapping("/delete")
    public String deleteImage(ImageVO imageVO){
        ResultDTO resultDTO = imageService.deleteImage(imageVO);
        return JSONObject.toJSONString(resultDTO);
    }

    @GetMapping("/findAll")
    public String deleteImage(){
        ResultDTO allImage = imageService.findAllImage();
        return JSONObject.toJSONString(allImage);
    }

    @PostMapping("/findById")
    public String findImageById(ImageVO imageVO){
        ResultDTO imageById = imageService.findImageById(imageVO);
        return JSONObject.toJSONString(imageById);
    }

    @PostMapping("/updateEnable")
    public String updateImageEnable(ImageVO imageVO){
        ResultDTO imageById = imageService.updateEnable(imageVO);
        return JSONObject.toJSONString(imageById);
    }

    @PostMapping("/update")
    public String updateImage(ImageVO imageVO){
        ResultDTO imageById = imageService.update(imageVO);
        return JSONObject.toJSONString(imageById);
    }
}
